package com.sichen.product.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sichen.product.entity.AttrAttrgroupRelationEntity;
import com.sichen.product.service.AttrAttrgroupRelationService;
import com.sichen.common.utils.PageUtils;
import com.sichen.common.utils.R;



/**
 * 属性&属性分组关联
 * @author sichen
 * @email 15837757959@163.com
 * @date 2022-05-14 14:44:51
 */
@RestController
@RequestMapping("product/attrattrgrouprelation")
public class AttrAttrgroupRelationController {
    @Autowired
    private AttrAttrgroupRelationService attrAttrgroupRelationService;

    /**
     * 查询(属性&属性分组)关联列表,并进行分页展示
     * @param params 前端传递的分页参数
     * @return 分页过的(属性&属性分组)列表数据
     */
    @RequestMapping("/list")
    //@RequiresPermissions("produck:attrattrgrouprelation:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrAttrgroupRelationService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 根据id查询对应的(属性&属性分组)单个数据
     * @param id (属性&属性分组表)的id
     * @return 根据(属性&属性分组表)的id查询的数据
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("produck:attrattrgrouprelation:info")
    public R info(@PathVariable("id") Long id){
		AttrAttrgroupRelationEntity attrAttrgroupRelation = attrAttrgroupRelationService.getById(id);
        return R.ok().put("attrAttrgroupRelation", attrAttrgroupRelation);
    }

    /**
     * 新增一条(属性&属性分组)数据
     * @param attrAttrgroupRelation (属性&属性分组)
     * @return 返回保存是否成功
     */
    @RequestMapping("/save")
    //@RequiresPermissions("produck:attrattrgrouprelation:save")
    public R save(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
		attrAttrgroupRelationService.save(attrAttrgroupRelation);
        return R.ok();
    }

    /**
     * 修改一条(属性&属性分组)数据
     * @param attrAttrgroupRelation 修改过的(属性&属性分组)
     * @return 返回修改是否成功
     */
    @RequestMapping("/update")
    //@RequiresPermissions("produck:attrattrgrouprelation:update")
    public R update(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
		attrAttrgroupRelationService.updateById(attrAttrgroupRelation);
        return R.ok();
    }

    /**
     * 批量删除(属性&属性分组)数据
     * @param ids 传递的(属性&属性分组表)的id数组
     * @return 返回删除是否成功
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("produck:attrattrgrouprelation:delete")
    public R delete(@RequestBody Long[] ids){
		attrAttrgroupRelationService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
